package tazadum.engine.sound;

import java.io.InputStream;

import tazadum.engine.Signal;
import tazadum.engine.TimeProvider;
import flumsynth.PPlayer;
import flumsynth.PSong;

public class Sound {
	private final PPlayer player;
	private final PSong song;

	public Sound(final TimeProvider timeProvider, final Signal signal) {
		this.player = new PPlayer(signal, timeProvider);
		this.song = new PSong(player);
	}
	
	public void fadeOut(float time, float duration) {
		player.fadeOut(time, duration);
	}

	public void start() {
		player.start();
	}

	public void stop() {
		player.stop();
	}

	public void initialize() {
		try {
			final InputStream stream = this.getClass().getClassLoader().getResourceAsStream("edizone.4ks");
			song.read(stream);
			stream.close();
		} catch (final Exception e) {
			throw new RuntimeException(e);
		}
	}

}
